// 1.点击开始抽奖按钮
// 2.假设奖品停在下标为3
let startBtn = document.querySelector(".startBtn");
let targetIndex = Math.floor(Math.random() * 8);
let lis = document.querySelectorAll("li:not(.startBtn)");
let nowIndex = 0;
let lastIndex = 0;
let pathArr = [0, 1, 2, 4, 7, 6, 5, 3];
let count = 0;
let Timer
let isRun = true;

// 定义行走的路径规则

	startBtn.addEventListener("click", function() {
		if (isRun) {
			isRun = false;
			Timer = setInterval(function() {
				Run()
			}, 300)
		} else {
			Run()
		}
	})


function Run() {

	count++;
	lis[pathArr[lastIndex]].classList.remove("active");
	lis[pathArr[nowIndex]].classList.add("active");
	console.log(count)
	lastIndex = nowIndex;
	(++nowIndex == lis.length) && (nowIndex = 0);

	if (count == 10 || count == 79) {
		clearInterval(Timer);
		Timer = setInterval(Run, 220);
	}
	if (count == 20 || count == 75) {
		clearInterval(Timer);
		Timer = setInterval(Run, 50);
	}
	if (count == 15 || count == 50) {
		clearInterval(Timer);
		Timer = setInterval(Run, 30);
	}
	if (count >= 80) {
		if (nowIndex == targetIndex) {
			clearInterval(Timer);
			isRun = true;

			// 重新开始
	
			nowIndex = 0;
			count = 0;
			targetIndex = Math.floor(Math.random() * 8);
		
		// 	startBtn.addEventListener("click", function() {
		// 		if (isRun) {
		// 			isRun = false;
		// 			Timer = setInterval(function() {
		// 				Run()
		// 			}, 300)
		// 		} else {
		// 			Run()
		// 		}
		// 	})
			
		}
	}
}






// 1.转10圈后在targetIndex停止 clearInterval(Timer)
// 2.速度变化规律 最多300毫秒 。最少20毫秒 由慢变快
// 3.动画过程不能再次点击
// 4.下次点击抽奖保证从头开始
